package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.interfaces.CheckItemService;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.resources.entity.QueryPageBean;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {

    @Override
    public Map findPageByContion(QueryPageBean queryPageBean) {
        //条件构造器
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<>();
        String queryString = queryPageBean.getQueryString();//查询条件
        queryWrapper.like("name", queryString == null ? "" : queryString);//模糊查询分页
        queryWrapper.eq("is_delete", 0);// 有效数据
        //分页请   求数据
//        Page<CheckItem> page = page(new Page<CheckItem>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()),queryWrapper);
        Page<CheckItem> page = page(new Page<CheckItem>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()), queryWrapper);
        List<CheckItem> records = page.getRecords();//将数据封装成list数据类型
        long total = page.getTotal();
        Map map = new HashMap(); //定义一个map对象封装分页查询结果集数据
        map.put("list", records); // 分页数据
        map.put("total", total); //总记录数
        return map;
    }

    @Override
    public List<CheckItem> findAll() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("is_delete", 0);
        List<CheckItem> list = list(queryWrapper);
        return list;
    }

    @Override
    public List<Integer> findCheckItemIdsByGroupId(int id) {
        return baseMapper.findCheckItemIdsByGroupId(id);
    }
}
